<?php

/**
 * Description of LeagueDao_Class
 *
 * @author aziz
 */

require_once $_SERVER['DOCUMENT_ROOT'] . '/portal/domain/Season_Class.php';
require_once 'GenericDAO_Class.php';
require_once 'LeagueDAO_Class.php';

class SeasonDAO extends GenericDAO {

    public $leagueDAO;

    public function __construct() {
        $this->leagueDAO=new LeagueDAO();
    }

    public function prepareService($module, $id, $object) {
        $this->type = SEASON_SERVICE_MOD;
        $this->module = $module;
        $this->id = $id;
        $this->object = $object;
        $this->__setUp();
    }

    public function loadAll() {
        $this->prepareService(SERVICE_ALL, null, null);
        $sezonlar = $this->getRequest();
        for ($i = 0; $i < count($sezonlar); $i++) {
            $season = new Season();
            $season->setId($sezonlar[$i]->id);
            $season->setName($sezonlar[$i]->name);
            $season->setLeague($this->leagueDAO->loadById($sezonlar[$i]->league->id));
            $season->setSeasonType($sezonlar[$i]->seasonType);
            $season->setStatus($sezonlar[$i]->status);
            $seasons[] = $season;
        }
        return $seasons;
    }

    public function loadById($id) {
        $this->prepareService(SERVICE_SINGLE, $id, null);
        $sezon = $this->getRequest();
        $season = new Season;
        $season->setId($sezon->id);
        $season->setName($sezon->name);
        $season->setLeague($this->leagueDAO->loadById($sezon->league->id));
        $season->setSeasonType($sezon->seasonType);
        $season->setStatus($sezon->status);
        $season->setShortName($sezon->shortName);
        $season->setAbbreviation($sezon->abbreviation);
        return $season;
    }

    public function delete($id) {
        $this->prepareService(SERVICE_DELETE, $id, null);
        $this->deleteRequest();
    }

    public function upsert($season) {
        $this->prepareService(SERVICE_SAVE, null, $season);
        $this->postRequest();
    }

}

?>
